﻿{extend name="public:base" /}{block name="css"}
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css"/>
<link href="__ADMIN__/css/style.css" rel="stylesheet">

{/block}{block name="content"}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <form method="post">
                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">拨付周期（月）</label>
                                <div class="col-sm-3">
                                    <input type="number" class="form-control month" placeholder="按N个月拨付完毕" value="{:C('SETTLEMENT_MONTH')}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">拨付比例设置</label>
                            </div>
                        </div>

                        <div class="config-box">
                            {volist name="config_arr" id="vo"}
                            <div class="box-item">
                                <div class="form-group row">
                                    <label class="col-sm-1 col-form-label">第{$key+1}期（%）</label>
                                    <div class="col-sm-3">
                                        <input type="number" class="form-control config" min="1" max="100" placeholder="启动后第{$key+1}个月N%" value="{$vo}">
                                    </div>
                                </div>
                            </div>
                            {/volist}

                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="form-group row">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button type="button" class="btn btn-w-m btn-default back-page">返回</button>
                                <button type="button" class="btn btn-w-m btn-primary" onclick="save()">保存设置</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>{/block}

{block name="js"}
<script>
    $('.month').on('input' ,function () {
        var month = $(this).val();
        var html = '';
        for (var i = 1; i <= month; i++) {
            html += '<div class="box-item">\n' +
              '                                <div class="form-group row">\n' +
              '                                    <label class="col-sm-1 col-form-label">第' + i + '期（%）</label>\n' +
              '                                    <div class="col-sm-3">\n' +
              '                                        <input type="number" class="form-control config" min="1" max="100" placeholder="启动后第' + i + '个月N%">\n' +
              '                                    </div>\n' +
              '                                </div>\n' +
              '                            </div>';
        }

        $('.config-box').html(html);
    })

    function save() {
        var month = parseInt($('.month').val());
        if (month > 0) {
            var config = '';
            for (var i = 0; i < month; i++) {
                var value = parseInt($('.config').eq(i).val());
                if (config == '') {
                    config = value;
                } else {
                    config += ',' + value;
                }
            }

            $.post("{:url('settlementConfig')}", {month, config}, res => {
                if (res.result == 1) {
                    layer.msg(res.msg, {icon: 1, time: 1000}, function () {
                        window.location.reload();
                    })
                } else {
                    layer.msg(res.msg);
                }
            }, 'JSON')
        } else {
            layer.msg('请输入拨付周期');
        }
    }

</script>{/block}